package cn.edu.hunau.oop.day06;

import org.junit.Test;

/**
 * @author hb
 * @date 2025-08-11 10:21:31
 */
public class RegexTest {

    @Test
    public void test01(){
        match("400112","[0-9]{6}");
        match("4001120","[0-9]{6}");
        match("13412341234","1[3-9][0-9]{9}");
        match("12412341234","1[3-9][0-9]{9}");
    }

    @Test
    public void test02(){
        match("400112","\\d{6}");
        match("4001120","\\d{6}");
        match("13412341234","1[3-9]\\d{9}");
        match("12412341234","1[3-9]\\d{9}");
    }

    @Test
    public void test03(){

        String s1 = "123abc2134asdf".replaceAll("\\d+", "*");
        System.out.println(s1);
        String s2 = "1232134".replaceAll("^\\d+$", "*");
        System.out.println(s2);

        String s3 = "abc   ads sa sdfa   ".replaceAll("\\s+", "");
        System.out.println(s3);//abcadssasdfa
    }

    public void match(String value,String regex){
     System.out.println("正则:"+regex+",匹配值:"+value+",结果"+value.matches(regex));
    }
}
